package cn.bfay.lion.rest.controller;

import cn.bfay.lion.rest.annotation.Login;
import cn.bfay.lion.rest.param.WechatLoginParam;
import cn.bfay.lion.rest.service.UserService;
import cn.bfay.lion.rest.vo.UserVo;
import cn.bfay.lion.rest.vo.UserWatchVo;
import cn.bfay.web.result.ListResult;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * UserController.
 *
 * @author wangjiannan
 */
//@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/user")
public class UserController extends BaseController {
    private final UserService userService;

    @PostMapping("/wechat-login")
    public void wechatLogin(@Valid @RequestBody WechatLoginParam wechatLoginParam) {
        userService.wechatLogin(wechatLoginParam);
    }

    @Login
    @GetMapping("/check-login")
    public void checkLogin() {
    }

    @Login
    @GetMapping("/check-admin")
    public void checkAdmin() {
        userService.checkAdmin();
    }

    @Login
    @GetMapping("/get-all-user")
    public ListResult<UserVo> getAllUser() {
        return new ListResult<>(userService.getWechatUser());
    }

    @Login
    @GetMapping("/get-user-watch")
    public ListResult<UserWatchVo> getUserWatch(@RequestParam @ApiParam(value = "用户id") String openid) {
        return new ListResult<>(userService.getUserWatch(openid));
    }
}
